package com.hllxd.hism.star.basic.service.service;


import com.alibaba.fastjson.JSON;
import com.hllxd.hism.star.basic.service.dao.mapper.mis.DashboardMapper;
import com.hllxd.hism.star.basic.service.model.cost.CostReportEntity;
import com.hllxd.hism.star.basic.service.model.DashboardEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 消费报告
 *
 * @author lixiyong
 * @date 2020/12/20 16:15
 */
@Slf4j
@Service("dashboardService")
public class DashboardServiceImpl implements DashboardService {

    @Autowired
    private DashboardMapper dashboardMapper;

    final static String ZERO = "0";

    @Override
    public List<CostReportEntity> queryYarnQueue(String ownerID, String ptdate) {

        if (ownerID == null || ownerID.isEmpty() || ownerID.equals(ZERO)) {
            ownerID = null;
        }
        return dashboardMapper.queryYarnQueue(ownerID, ptdate);
    }

    @Override
    public List<CostReportEntity> queryHdfsTable(String ownerID, String ptdate) {

        if (ownerID == null || ownerID.isEmpty() || ownerID.equals(ZERO)) {
            ownerID = null;
        }
        return dashboardMapper.queryHdfsTable(ownerID, ptdate);
    }

    @Override
    public List<DashboardEntity> loadDashboard(String type) {
        return dashboardMapper.loadDashboard(type);
    }

    @Override
    public Long setDashboard(DashboardEntity entity) {
        log.info("set param: {}", JSON.toJSONString(entity));
        if (entity.getId() == null || entity.getId() == 0) {
            entity.setAction(0);
            return dashboardMapper.insertDashboard(entity);
        } else {
            entity.setAction(1);
            return dashboardMapper.updateDashboard(entity);
        }
    }

    @Override
    public DashboardEntity getDashboard(Long id) {
        return dashboardMapper.getDashboard(id);
    }
}
